package com.lagou.comment.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lagou.comment.api.CourseCommentRemoteService;
import com.lagou.comment.api.dto.CourseCommentDTO;
import com.lagou.comment.api.param.CourseCommentParam;
import com.lagou.comment.entity.CourseComment;
import com.lagou.comment.service.ICourseCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author dingchengyu
 * @since 2022-01-30
 */
@RestController
@RequestMapping("/comment")
public class CourseCommentController {

    @Autowired
    private CourseCommentRemoteService courseCommentRemote;

    @Autowired
    private ICourseCommentService courseCommentService;

    @PostMapping(value = "/saveCourseComment",consumes = "application/json")
    public boolean saveCourseComment(@RequestBody CourseCommentDTO commentDTO){
        return courseCommentRemote.saveCourseComment(commentDTO);
    }

    /**
     * 获取课程或课时下的用户评论,
     *
     * @return
     */
    @PostMapping("/getCourseCommentList")
    public List<CourseCommentDTO> getCourseCommentList(@RequestBody CourseCommentParam courseCommentParam){
        return courseCommentRemote.getCourseCommentList(courseCommentParam);
    }

    @GetMapping("/listDemo")
    public Page<CourseComment> getCourseCommentList(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize){
        return courseCommentService.getCourseCommentList(pageNum, pageSize);
    }

    /**
     * 逻辑删除课程评论
     *
     * @param commentId
     * @param userId
     * @return
     */
    @GetMapping("/deleteCourseComment")
    public boolean deleteCourseComment(@RequestParam("commentId") String commentId,
                                @RequestParam("userId") Integer userId){
        return courseCommentRemote.deleteCourseComment(commentId,userId);
    }

}
